package domain.service;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;

import javax.jdo.PersistenceManager;

import domain.data.QnAPersistenceManager;


public class Test {
	public Test()
	{
		try
        {
			PersistenceManager psm = QnAPersistenceManager.get().getPersistenceManager();
			String domain = "abc.20w.com.vn";
			String re_domain = domain;
			re_domain = re_domain.replaceAll("com[.]{1}[a-zA-Z]+$", "");
	        File file = new File("/home/vdc/workspace/java/domain/src/domain.txt");
	        BufferedReader reader = new BufferedReader(new FileReader(file));
	        String line = "";
	        while((line = reader.readLine()) != null)
	        {
	        	String[] check = line.split(" ");
	        	for(int i=0;i<check.length;i++)
	        	{
	        		re_domain = re_domain.replaceAll(check[i], "");
	        	}
	        }
	        reader.close();
	        
	        if(re_domain.length() != domain.length())
	        {
	        	System.out.println(re_domain.replaceAll("[.]+$", "").replaceAll("^[a-zA-Z]+[.]{1}", ""));
	        	System.out.println("domain");
	        } else {
	        	System.out.println(re_domain.replaceAll("[.]{1}[a-zA-Z]+$", "").replaceAll("^[a-zA-Z]+[.]{1}", ""));
	        	System.out.println("sub domain");
	        }	        
	    }
	    catch (IOException ioe)
	    {
	        ioe.printStackTrace();
	    }
	}
	public static void main( String args[])
	{
		new Test();
	}
}
